import java.util.Arrays;

public class Solution1170 {
    public int[] numSmallerByFrequency(String[] queries, String[] words) {
        int[] f=new int[11];
        for (String word : words) {
            f[f(word)]++;
        }
        int[] ans=new int[queries.length];
        for (int i=0;i<queries.length;i++) {
            String query=queries[i];
            int c=f(query);
            for (int j=c+1;j<=10;j++){
                ans[i]+=f[j];
            }
        }
        return ans;
    }

    public int f(String word){
        char min='z'+1;
        int count=0;
        for (char c : word.toCharArray()) {
            if (c<min){
                min=c;
                count=0;
            }
            if (c==min){
                count++;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1170().numSmallerByFrequency(new String[]{"bbb", "cc"}, new String[]{"a", "aa", "aaa", "aaaa"})));
    }
}
